<?php

namespace Parse;

class MultiParser extends Parser
{
    public function __construct($parser, $callback = null)
    {
        $this->parsers = array($parser);
        parent::__construct($callback);
    }

    public function defaultCallback()
    {
        return func_get_args();
    }

    public function matchProcedure($string)
    {
        $matches = array();
        try {
            while (strlen($string) > 0) {
                $result = $this->parsers[0]->match($string);
                $matches[] = $result["match"];
                $string = $result["rest"];
            }
        } catch (ParseException $e) {
        }
        return array("matches" => $matches,
                     "rest" => $string);
    }
}
